
import Vue from 'vue'
import Vuex from 'vuex'

import {
  setItem,
  getItem,
  removeItem
} from '@/utils/Storage'

Vue.use(Vuex)

const  TOKEN_KEY = 'TOKEN_KEY' // 把字符串存到变量中，以后就只用这个变量， 防止命名冲突

export default new Vuex.Store({
  state: {

    flag: true,

    userToken: getItem(TOKEN_KEY) || null

  },
  mutations: {
    change(state) {
       if( state.userToken){
         state.flag = !state.flag
       }
     
    },

    setUser(state, data) {
      state.userToken = data     
      setItem(TOKEN_KEY, state.userToken)
    },
    removeUser(state) {
      removeItem(TOKEN_KEY)
      state.userToken = null    
      
    }
  },
  actions: {},
  modules: {}
})
